//dp[i]表示以i字符结尾的最长长度，最后全部加起来即可
import java.util.Arrays;

public class Solution467 {
    public int findSubstringInWraproundString(String p) {
        int[] dp=new int[26];
        int k=1;
        dp[p.charAt(0)-'a']=1;
        for (int i=1;i<p.length();i++){
            if (con(p,i)){
                k++;
            }else{
                k=1;
            }
            dp[p.charAt(i)-'a']=Math.max(dp[p.charAt(i)-'a'],k);
        }
        return Arrays.stream(dp).sum();
    }

    private boolean con(String p, int i) {
        char c1=p.charAt(i);
        char c2=p.charAt(i-1);
        if (c1=='a'){
            return c2=='z';
        }else{
            return c1-c2==1;
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution467().findSubstringInWraproundString("zab"));
    }
}
